<?php
	defined('RUN') or die('No access');

	class HomeController
	{
		public function index()
		{
			$data = Model::get('website')->getLayoutData();
            
            $tong = Model::get('product')->toTotalHome(9);
            
            $product = Model::get('product')->getProductHome("*", 9, 3, 0);
            foreach($product as $row){
                $price_sale = ($row['price']!=0 && $row['per']!=0)?((100-$row['per'])*$row['price']/100):$row['price'];
                $data['trangchu'][] = array(
                    'id'        => $row['id'],
                    'name'      => $row['name'],
                    'content_short' => $row['content_short'],
                    'images'    => $row['images'],
                    'price'     => $row['price'],
                    'per'       => $row['per'],
                    'company'   => $row['company'],
                    'address'   => $row['address'],
                    'phone'     => $row['phone'],
                    'date_start'=> $row['date_start'],
                    'date_end'  => $row['date_end'],
                    'view'      => $row['view'],
                    'price_sale'=> number_format($price_sale,0,".",","),
                );
            }
			
			$data['loader']= $product = Model::get('product')->getProductHome("*", 9, 15, 4);
            $data['noibat'] = Model::get('product')->getProduct("*",10);
            $data['khoahocmoi'] = Model::get('product')->getProduct("*",11);
			
			$data['content_file'] = 'home/index.tpl';
			View::load('layout.tpl', $data, $data['temp']);
		}
	
        public function load()
		{
            $newscat_id=addslashes(9);
			$num=addslashes(1);
			$recordPerPage =intval($num)*10;
			$cond = "`category`=".$newscat_id." order by `sort` ASC, `id` DESC LIMIT 0$recordPerPage OFFSET 4";
			$data['listNewsCat'] = Model::get('product')->getProductSQL("*", $cond);
			View::load('load.tpl', $data, 'default');
			
		}
	}
